#include <iostream>
#include <fstream>
#include <unordered_map>
#include <string>

namespace dict_ns
{
    const std::string path = "./Dict.txt";
    const std::string sep = ": ";
class Dict
{
private:
    void Load()
    {
        std::ifstream in(_conf_path, std::ios::in);
        if(!in.is_open())
        {
            std::cout << "load fail\n";
            exit(0);
        }
        std::string message;
        while(getline(in, message))
        {
            //空行
            if(message.empty())
                continue;
            auto pos = message.find(sep);
            if(pos == std::string::npos)
                continue;
            std::string word = message.substr(0, pos);
            if(word.empty())
                continue;
            std::string han = message.substr(pos + sep.size());
            if(han.empty())
                continue;
            
            _dict[word] = han;
        }
    }
public:
    Dict(const std::string pathName = path)
        :_conf_path(path)
    {
        Load();
    }
    std::string require(const std::string word)
    {
        if(_dict.count(word))
            return _dict[word];
            
        return "Not Found";
    }
    ~Dict()
    {}
private:
    std::string _conf_path;
    std::unordered_map<std::string, std::string> _dict;
};
}